<template>
  <div>
    <el-tabs @tab-click="handleClick" type="card" v-model="activeName">
      <el-tab-pane v-if="showTempTabs" label="公式发布" name="first">
        <TempAndReleaseTable v-if="activeName === 'first'" ref="releasedCalculator" :showStatus="this.showDetail"
                             @released="refreshSyncTable"></TempAndReleaseTable>
      </el-tab-pane>
      <el-tab-pane v-if="showSyncTabs" label="公式推送" name="second">
        <MedicalCalculatorSyncTable v-if="activeName === 'second'"
                                    ref="syncCalculatorTable"></MedicalCalculatorSyncTable>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import TempAndReleaseTable from "../../components/calculator/TempAndReleaseTable"
import MedicalCalculatorSyncTable from "./MedicalCalculatorSyncTable";

export default {
  name: "ReleaseAndSyncTab",
  components: {
    TempAndReleaseTable,
    MedicalCalculatorSyncTable
  },
  data() {
    return {
      activeName: 'first',
      showTempTabs: false,
      showSyncTabs: false,
      showDetail: ''
    };
  },
  methods: {
    handleClick(tab, event) {
    },
    refreshSyncTable() {
      this.$refs.syncCalculatorTable.getTableData()
    }
  },
  activated() {
    if (this.$route.meta.isUseCache) {
      this.$refs.syncCalculatorTable.getTableData()
      this.$refs.releasedCalculator.getTableData()
      return
    }
    if (this.$store.state.user.userName === 'admin') {
      this.showSyncTabs = true
      this.showTempTabs = true
      this.showDetail = 'false'
      return
    }
    //角色Id等于管理员角色
    for (let i = 0; i < this.$store.state.user.roleIds.length; i++) {
      if (this.$store.state.user.roleIds[i] === '1455781731549327361') {
        this.showSyncTabs = true
        this.showTempTabs = true
        this.showDetail = 'false'
        return;
      }
    }
    UTIL.findTreeNode(this.$store.state.menuList, item => {

      if (item.id === this.$store.state.activeId) {
        this.showSyncTabs = true
        this.showTempTabs = true
        if (item.editButton || item.detailButton) {
          this.showTempTabs = true
          this.showSyncTabs = false
          if (item.editButton && item.detailButton) {
            this.showDetail = 'false'
          } else {
            if (item.detailButton) {
              this.showDetail = "true"
            }
          }
        }
        if (item.pushButton && item.editButton) {
          this.showSyncTabs = true
          this.showTempTabs = true
          this.activeName = 'first'
          this.showDetail = 'false'
        } else {
          if (item.pushButton && item.detailButton) {
            this.showSyncTabs = true
            this.showTempTabs = true
            this.activeName = 'first'
            this.showDetail = "true"
          } else {
            if (item.pushButton) {
              this.showSyncTabs = true
              this.showTempTabs = false
              this.activeName = 'second'
            }
          }
        }
      }
    })
  }
}
</script>

<style scoped>

</style>
